mod accrual_test {
    use fixed_macro::fixed;

    use rust_ledger::accrual::{Side, Accrual};

     #[test]
    fn sides() {
        
        {
            let mut acrl = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};
            assert_eq!(Side::DR, acrl.side());
            assert_eq!(Side::CR, acrl.counter_side());

            acrl.swap();
            assert_eq!(Side::CR, acrl.side());   
            assert_eq!(Side::DR, acrl.counter_side());
        }

        {
            let acrl = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(1000: I28F4), swapped: false};
            assert_eq!(Side::BOTH, acrl.side());   
            assert_eq!(Side::ZERO, acrl.counter_side());   
        }

        {
            let acrl = Accrual {dr: fixed!(0: I28F4), cr: fixed!(0: I28F4), swapped: false};
            assert_eq!(Side::ZERO, acrl.side());   
            assert_eq!(Side::BOTH, acrl.counter_side());   
        }
    }

    #[test]
    fn inverse() {

        {
            let mut acrl = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};
            let counter = acrl.counter();
            assert_eq!(acrl.dr, counter.cr);
            assert_eq!(acrl.cr, counter.dr);

            acrl.swap();
            assert_eq!(acrl.cr, counter.cr);
            assert_eq!(acrl.dr, counter.dr);

            acrl.swap();
            assert_eq!(acrl.dr, counter.cr);
            assert_eq!(acrl.cr, counter.dr);
        }

    }

    #[test]
    fn plus() {

        let mut acrl = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};
        let     oper = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};

        acrl.plus(&oper);
        assert_eq!(fixed!(2000: I28F4), acrl.dr);

    }

    #[test]
    #[should_panic(expected = "Incompatible swapping condition")]
    fn invalid_plus() {

        let mut acrl = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};
        let     oper = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};

        acrl.swap();
        acrl.plus(&oper);

    }

    #[test]
    fn duct() {
        {
            let mut acrl = Accrual {dr: fixed!(2000: I28F4), cr: fixed!(0: I28F4), swapped: false};
            let     oper = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};

            let duct = acrl.duct(&oper);
            assert_eq!(fixed!(1000: I28F4), acrl.dr);

            assert_eq!(fixed!(1000: I28F4), duct.cr);
            assert_eq!(fixed!(   0: I28F4), duct.dr);
        }

        {
            let mut acrl = Accrual {dr: fixed!(2000: I28F4), cr: fixed!(0: I28F4), swapped: false};
            let mut oper = Accrual {dr: fixed!(1000: I28F4), cr: fixed!(0: I28F4), swapped: false};

            oper.swap();

            let duct = acrl.duct(&oper);
            assert_eq!(fixed!(2000: I28F4), acrl.dr);
            assert_eq!(fixed!(   0: I28F4), acrl.cr);

            assert_eq!(fixed!(   0: I28F4), duct.dr);
            assert_eq!(fixed!(   0: I28F4), duct.cr);
        }    
    }
}

